    <?php
    if (isset($_POST['fname']))
    {
    $fname = trim($_POST['fname']);
    $lname = trim($_POST['lname']);
    $add = trim($_POST['add']);
    $phone = trim($_POST['phone']);
    $city = trim($_POST['city']);
    $sub = trim($_POST['sub']);
    $drink = trim($_POST['drink']);
    $note = trim($_POST['note']);
    $fields = array('fname', 'lname', 'add', 'phone', 'city', 'sub', 'drink');
    $top = array ();

    }

        //create array of toppings after looking to see if they
        //exist in the $_post array
        if(array_key_exists('t1', $_POST) == 1){
            $top[] = "lettice";
        }
        if(array_key_exists('t2', $_POST) == 1){
            $top[] = 'tomato';
        }
        if(array_key_exists('t3', $_POST) == 1){
            $top[] = 'cheese';
        }
        if(array_key_exists('t4', $_POST) == 1){
            $top[] = 'pickles';
        }
        if(array_key_exists('t5', $_POST) == 1){
            $top[] = 'onion';
        }

    //make sure the inputs are not too long
    //give error if they are
    function length_check($field, $length = 50)
    {
        if (strlen($_POST[$field]) < $length)
                return TRUE;
        else
                return FALSE;
    }

    foreach ($fields as $value) {
        if ( ! length_check($value))
        die("$value should be less than 50 characters");
    }

    //make sure the required fields are submitted
    //give error if not
    function submit_test($field)
    {
        if (isset($_POST[$field]) && $_POST[$field] != '')
                return TRUE;
        else
                return FALSE;
    }

    function show_error($message){
        echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
        echo "<html><head><title></title></head><body>";
        echo "$message left blank. All fields must be filled out";
        echo "</body></html>";
    }

    foreach ($fields as $submitted)
        if ( ! submit_test($submitted)){
            show_error($submitted);
            exit ();
        }

    //returns the cost of the sub
    function calc_cost($base_price, $num_topping){
        return $base_price + $num_topping * .5;
    }

    
    ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title></title>
</head>
    <body>

        <?php
        //set up summary output for order
    
        echo "<h1>PhP Sub Shop</h1>";
        echo "<p>Order Information </p>";
        echo "<p>Customer Name: $fname $lname</p>";
        echo "<p>Address: $add $city, FL</p>";
        echo "<p>Order: $sub sub <br />";
            foreach($top as $list){
                echo "--- $list <br />";
            }
        echo "</p>";
        echo "<p>Drink: $drink</p>";
        echo "<p>Notes: $note</p>";
        echo "<p>Price:$" . calc_cost(1.5, count($top)) . "</p>";

        ?>

    </body>
</html>
